/*
 * @Description: 
 * @Author: chenjiaxin
 * @Date: 2021-12-26 11:05:33
 * @LastEditTime: 2021-12-26 21:49:08
 * @FilePath: \novel-serve\src\service\article.service.js
 */

const connection = require("../app/database");
const errorTypes = require("../constants/error-types");

class ArticleService {
  async create (user_id, title, content) {
    const statement = `INSERT INTO article (user_id, title, content) VALUES (?, ?, ?);`;
    const result = await connection.execute(statement, [user_id, title, content]);
    return result[0];
    
  }

  async getArticleById (id) {
    const statement = `SELECT * FROM article WHERE id = ?;`;
    const [ result ] = await connection.execute(statement, [id]);
    return result[0];
  }
}

module.exports = new ArticleService();
